<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
    <%@ include file="/platform/style.jsp"%>
</head>
<style>
    .serch{
        margin: 5px;
        padding: 4px 10px;
        background: #1C84C6;
        border-radius: 5px;
        color: #fff;
        text-decoration: none;
    }
    .ui_btn_4{
        background-color: #c9c9c9;
    }
    .datainp{
        width:180px;
        height:23px !important;
        border:1px #A5D2EC solid;
    }
    .wicon{
        background-image: url(
        "");
        background-repeat:no-repeat;
        background-position:right center;
    }
    #errormsg{
        position: fixed;
        width: 200px;
        height: 50px;
        line-height: 50px;
        padding: 1px 5px;
        text-align: center;
        background-color: #00A4F2;
        opacity: 0.5;
        color: #fff;
        left: 50%;
        margin-left: -50px;
        top: 50%;
        border-radius: 20px;
    }
</style>
<body class="easyui-layout">
<div data-options="region:'center'" class="bodybg">
    <!-- 查询区域 -->
    <form id="queryForm" action="/marketing/FullGiftsPromotionPage.page" method="post">
        <div id="errormsg" style="display: none;"></div>
        <div class="panel">
            <div class="easyui-panel ui-queryBar panel-body panel-body-noheader panel-body-noborder" border="false" data-options="doSize:false" title="">
                <w:hidden bind="bean.id" />
                <w:hidden bind="pageNum"/>
                <w:hidden bind="pageSize_"/>
                <table cellpadding="0" cellspacing="0" style="margin-top:5px">
                    <tbody>
                    <tr>
                        <td width="80" align="right">活动标题：</td>
                        <td><w:text bind="bean.name" style="width:150px;" /></td>
                        <td width="80" align="right">推广平台：</td>
                        <td>
                            <select name="bean.platform" class=”easyui-combobox” style="height: 26px;width: 80px;">
                                <option value="">全部</option>
                                <w:option bind="bean.platform" value="0">全平台</w:option>
                                <w:option bind="bean.platform" value="1">PC端</w:option>
                                <w:option bind="bean.platform" value="2">微商城</w:option>
                            </select>
                        </td>
                        <td width="80" align="right">活动状态：</td>
                        <td>
                            <select name="bean.state" class=”easyui-combobox” style="height: 26px;width: 80px;">
                                <option value="">全部状态</option>
                                <w:option bind="bean.state" value="0">已暂停</w:option>
                                <w:option bind="bean.state" value="1">未开始</w:option>
                                <w:option bind="bean.state" value="3">已失效</w:option>
                                <w:option bind="bean.state" value="2">进行中</w:option>
                            </select>
                        </td>
                        <td width="80" align="right">开始时间：</td>
                        <td><input class="datainp wicon" id="giftsListInpstart" name="bean.start" type="text" placeholder="请选择" value="<w:write bind='bean.start'></w:write>"  readonly></td>
                        <td width="80" align="right">结束时间：</td>
                        <td><input class="datainp wicon" id="giftsListInpend" name="bean.end" type="text" placeholder="请选择" value="<w:write bind='bean.end'></w:write>"  readonly></td>
                        <td><a href="javascript:void(0)" class="serch" onclick="query()">查询</a></td>
                    </tr>
                    </tbody>
                </table>
            </div>
            <script>
                //实现日期选择联动
                var start = {
                    format: 'YYYY-MM-DD',//日期格式
                    minDate: '2014-06-16 23:59:59', //设定最小日期为当前日期
                    maxDate: '2099-12-31 23:59:59', //最大日期
                    festival: true,//是否显示节日
                    isClaer: true,//是否显示清空
                    isinitVal: false,//是否初始化时间
                    zIndex: 10000,//层级高度
                    choosefun: function (elem, datas) {
                        end.minDate = datas; //开始日选好后，重置结束日的最小日期
                        endDates();
                    },//选中日期回调
                    okfun: function (elem, datas) {
                        alert(datas)
                    }//点击确定回调
                };
                var end = {
                    format: 'YYYY-MM-DD',//日期格式
                    minDate: '2014-06-16 23:59:59', //设定最小日期为当前日期
                    maxDate: '2099-06-16 23:59:59', //最大日期
                    festival: true,//是否显示节日
                    isClaer: true,//是否显示清空
                    isinitVal: false,//是否初始化时间
                    zIndex: 10000,//层级高度
                    choosefun: function (elem, datas) {
                        start.maxDate = datas; //将结束日的初始值设定为开始日的最大日期
                    }
                };
                //日期联动
                function endDates() {
                    end.trigger = false; //结束日期的事件改成false
                    $("#giftsListInpend").jeDate(end);
                }
                $("#giftsListInpstart").jeDate(start);
                $("#giftsListInpend").jeDate(end);
            </script>
        </div>
        <div class="easyui-panel ui-toolBar" border="false" data-options="doSize:false">
            <a href="javascript:;" class="easyui-linkbutton" plain="true" onclick="fullgiftsAdd()">创建满赠促销</a>
        </div>
        <div class="ui_line" style="margin-top:10px"></div>
        <!-- 数据列表区域 -->
        <table class="ui-table" width="100%" cellpadding="1" cellspacing="1" data-options="showPage:true,pageNum:<w:write bind="pageNum"/>,pageSize:<w:write bind="pageSize_"/>,total:<w:write bind="pagination.totalCount"/>">
            <thead>
                <tr class="ui_th">
                    <td width="30" align="center"><input type="checkbox"></td>
                    <td>活动编号</td>
                    <td>推广平台</td>
                    <td>活动标题</td>
                    <td>开始时间</td>
                    <td>结束时间</td>
                    <td>参与方式</td>
                    <td>排序</td>
                    <td>活动状态</td>
                    <td width="110" align="center">操作</td>
                </tr>
            </thead>
            <tbody>
                <w:iterate id="info" bind="resultList_">
                    <tr class="ui_td">
                        <input disabled="disabled" type="hidden" name="id" value="<w:write bind="#info.id"/>">
                        <td align="center"><input type="checkbox" name="primaryKey_" value=""></td>
                        <td><w:write bind="#info.id" /></td>
                        <w:switch>
                            <w:case bind="#info.platform.toString == 0">
                                <td>全平台</td>
                            </w:case>
                            <w:case bind="#info.platform.toString == 1">
                                <td>PC端</td>
                            </w:case>
                            <w:case bind="#info.platform.toString == 2">
                                <td>微商城</td>
                            </w:case>
                        </w:switch>
                        <td><w:write bind="#info.productname"/></td>
                        <td><w:write bind="#info.start_time"/></td>
                        <td><w:write bind="#info.end_time"/></td>
                        <%--<td><w:write bind="#info.goods"/></td>--%>
                        <w:define id="info_product_type" bind="#info.product_type"/>
                        <w:switch>
                            <w:case bind="#info_product_type ==0 || #info_product_type==1 || #info_product_type==2">
                                <td><w:write bind="#info.goods"/></td>
                            </w:case>
                            <w:case bind="#info_product_type ==3">
                                <td><w:write bind="#info.classname"/></td>
                            </w:case>
                            <w:case bind="#info_product_type ==null">
                                <td></td>
                            </w:case>
                        </w:switch>
                        <td><w:write bind="#info.sort_value"/></td>
                        <w:define id="info_newtime" bind="#info.newtime" ></w:define>
                        <w:define id="info_startmsec" bind="#info.startmsec" ></w:define>
                        <w:define id="info_endmsec" bind="#info.endmsec" ></w:define>
                        <w:define id="info_state" bind="#info.state" ></w:define>
                        <w:switch>
                            <!-- 未开始 -->
                            <w:case bind=" #info_newtime < #info_startmsec ">
                                <w:switch>
                                    <w:case bind="#info_state == 0">
                                        <td>已暂停</td>
                                        <td><a href="javascript:void(0);" class="ui_btn marginR8"
                                               onclick="fullgiftsedit(<w:write bind="#info.id"/>)">编辑</a>
                                            <a href="javascript:;" class="ui_btn_2 continc" plain="true"
                                               onclick="startState(<w:write bind="#info.promotionid"/>)">继续</a>
                                        </td>
                                    </w:case>
                                    <w:case bind="#info_state == 1">
                                        <td>未开始</td>
                                        <td><a href="javascript:void(0);" class="ui_btn marginR8"
                                               onclick="fullgiftsedit(<w:write bind="#info.id"/>)">编辑</a>
                                            <a href="javascript:;" class="ui_btn_2" plain="true"
                                               onclick="delefullgifts(<w:write bind="#info.id"/>)">删除</a>
                                        </td>
                                    </w:case>
                                </w:switch>
                            </w:case>
                            <!-- 进行中 -->
                            <w:case bind=" #info_newtime >= #info_startmsec && #info_newtime < #info_endmsec">
                                <w:switch>
                                    <w:case bind="#info_state == 1">
                                        <td>进行中</td>
                                        <td><a href="javascript:void(0);" class="ui_btn marginR8"
                                               style="background-color:#c9c9c9;">编辑</a>
                                            <a href="javascript:;" class="ui_btn_2" id="stopActivity" plain="true" onclick="stopState(<w:write bind="#info.id"/>)">暂停</a>
                                        </td>
                                    </w:case>
                                    <w:case bind="#info_state == 0">
                                        <td>已暂停</td>
                                        <td><a href="javascript:void(0);" class="ui_btn marginR8"
                                               onclick="fullgiftsedit(<w:write bind="#info.id"/>)">编辑</a>
                                            <a href="javascript:;" class="ui_btn_2 continc" plain="true"
                                               onclick="startState(<w:write bind="#info.id"/>)">继续</a>
                                        </td>
                                    </w:case>
                                </w:switch>
                            </w:case>
                            <!-- 已过期 -->
                            <w:case bind=" #info_newtime >= #info_endmsec ">
                                <td>已失效</td>
                                <td><a href="javascript:void(0);" class="ui_btn marginR8" onclick="fullgiftsedit(<w:write bind="#info.id"/>)">编辑</a>
                                    <a href="javascript:;" class="ui_btn_2" onclick="delefullgifts(<w:write bind="#info.id"/>)" plain="true">删除</a>
                                </td>
                            </w:case>
                        </w:switch>
                    </tr>
                </w:iterate>
            </tbody>
        </table>
    </form>
</div>
</body>
</html>
<script>
    function query() {
        $w.execForm({pageNum: 1})
    }
    function fullgiftsAdd() {
        $w.openDialog({
            url: ctx + '/marketing/FullGiftsPromotionPage@fullGiftsAdd.page',
            title: "创建满赠促销",
            w: 700,
            h: 450,
            maximized: true,
            afterClose: function (re) {
                if (re) {
                    query();
                }
            }
        });
    }
    /*点击编辑按钮，单项*/
    function fullgiftsedit(id) {
        $w.openDialog({
            url: ctx + '/marketing/FullGiftsPromotionPage@show.page?bean.id=' + id,
            title: "编辑满赠促销",
            w: 700,
            h: 450,
            maximized: true,
            afterClose: function (re) {
                query(re);
            }
        })
    }
    /*点击暂停按钮*/
    function stopState(id) {
        var data = {"bean.promotionid": id}
        if ($("#stopActivity").html() == "暂停"){
            $("#errormsg").html("活动已暂停").fadeIn(300).delay(2000).fadeOut(300);
        }
        /*延迟执行*/
        setTimeout(function () {
            $w.doUrl(ctx + "/marketing/FullGiftsPromotionPage@FullGiftsUpDataStop.page?bean.state=0", data, function () {
                query()
            })
        }, 2000);
    }
    /*点击继续按钮*/
    function startState(id) {
        var data = {"bean.promotionid": id}
        if ($(".continc").html() == "继续"){
            $("#errormsg").html("活动已开启").fadeIn(300).delay(2000).fadeOut(300);
        }
        /*延迟执行*/
        setTimeout(function () {
            $w.doUrl(ctx + "/marketing/FullGiftsPromotionPage@FullGiftsUpDataStop.page?bean.state=1", data, function () {
                query()
            })
        }, 2000);
    }
    /*点击删除按钮，单项*/
    function delefullgifts(id) {
        $.messager.confirm('删除提示', '确定删除此活动吗?',function (r) {
            if (r){
                var data = {"bean.promotionid": id}
                $("#errormsg").html("活动已删除").fadeIn(300).delay(2000).fadeOut(300);
                setTimeout(function () {
                    $w.doUrl(ctx + "/marketing/FullGiftsPromotionPage@FullGiftsUpDataStop.page?bean.state=2", data, function () {
                        query()
                    })
                }, 2000);
            }
        })
    }
</script>


